package com.lib.controller.user;

import com.lib.pojo.VO.CategoryVO;
import com.lib.pojo.entity.Category;
import com.lib.pojo.entity.Result;
import com.lib.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Tag(name = "分类图书接口")
@RestController
@RequestMapping("/user/categories")
@CrossOrigin(origins = "*")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    //1：根据分类ID查询图书
    @Operation(summary = "根据分类ID查询图书")
    @GetMapping("/categoryId")
    public Result<List<CategoryVO>> getCategory(Integer categoryId){
        List<CategoryVO> categoryVOS = categoryService.getCategoryById(categoryId);
        return Result.success(categoryVOS);
    }
    //2：返回分类名称及ID
    @Operation(summary = "返回分类名称")
    @GetMapping("/categoryName")
    public Result<List<Category>> getCategoryName(){
        List<Category> categoryName = categoryService.getCategoryName();
        return Result.success(categoryName);
    }
}
